package com.zb.controller;


import com.zb.entity.dto.AuthorDto;
import com.zb.result.Result;
import com.zb.search.SearchDto;
import com.zb.service.ZjAuthorService;
import com.zb.utils.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 系统权限菜单表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2024-02-17
 */
@Api(tags = "前台系统权限类接口")
@RestController
@RequestMapping("/author")
public class ZjAuthorController {
    @Resource
    private ZjAuthorService authorService;

    @ApiOperation("新增或修改权限")
    @PostMapping("/save")
    public Result save(@RequestBody @Valid AuthorDto authorDto) {
        authorService.save((authorDto));
        return Result.success(null == authorDto.getId()? "新增权限成功" : "修改权限成功");
    }

    @ApiOperation("获取菜单权限列表")
    @PostMapping("/getList")
    public Result getList(@RequestBody SearchDto search) {
        return Result.success("获取菜单权限列表成功").data(authorService.getList(search));
    }

    @ApiOperation(value = "批量启用或禁用菜单权限")
    @PutMapping("/disabled")
    public Result disabled(@RequestParam @ApiParam(value = "菜单权限状态：false-启用，true-禁用", required = true, example = "false") boolean status,
                           @RequestBody @ApiParam(value = "菜单权限ID", required = true) List<Long> ids) {
        authorService.updateDisabledBatchById(ids, status);
        return Result.success(status? "禁用菜单权限成功" : "启用菜单权限成功");
    }

    @ApiOperation("获取所有菜单权限")
    @GetMapping("/getAllAuthor")
    public Result getAllAuthor() {
        return Result.success("获取所有菜单权限成功").data(PageUtil.rows(authorService.getAllAuthor()));
    }



}
